package ui.juego

import dominio.ubicaciones.Pais
import java.awt.Color
import org.uqbar.arena.bindings.PropertyAdapter
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.windows.SimpleWindow
import org.uqbar.arena.windows.WindowOwner
import ui.juego.expedientes.ExpedientesSinEdicionWindow
import ui.juego.utilidades.IconUtils

class ResolverCasoWindow extends SimpleWindow<Investigacion> {
	
	new(WindowOwner parent, Investigacion model) {
		super(parent, model)
		title = '''Resolviendo: «modelObject.caso.nombre»'''
		iconImage = IconUtils.path
	}
	
	override protected addActions(Panel actionsPanel) {}
	
	override protected createFormPanel(Panel mainPanel) {}
	
	override createMainTemplate(Panel mainPanel) {
		val upPanel = new Panel(mainPanel) => [
			layout = new ColumnLayout(3)
		]
		
		createCasoPanel(upPanel)
		createPistasPanel(upPanel)
		new Panel(upPanel)
		new Label(mainPanel) => [
			heigth = 2
			background = Color.GRAY
		]
		val downPanel = new Panel(mainPanel) => [
			layout = new HorizontalLayout
		]
		createRecorridoCriminalPanel(downPanel)
		
		createDestinosFallidosPanel(downPanel)
	}
	
	def createCasoPanel(Panel owner) {		
		val casoPanel = new Panel(owner) => [
			layout = new VerticalLayout
		]
		val headPanel = new Panel(casoPanel) => [
			layout = new ColumnLayout(2)
		]
		val botoneraPanel = new Panel(casoPanel) => [
			layout = new VerticalLayout
		]
		
		new Label(headPanel) => [
			text = "Estás en:"
			fontSize = 12
		]
		new Label(headPanel) => [
			bindValueToProperty("paisActual.nombre")
			fontSize = 12
			foreground = Color.RED
		]
		
		new Button(botoneraPanel) => [
			caption = "Orden de Arresto"
			background = Color.ORANGE
			width = 150
			bindEnabledToProperty("ordenNoEmitida")
			onClick[ | 
				new EmitirOrdenDeArrestoDialog(this, new EmitirOrdenDeArresto(modelObject)).open
			]
		]
		new Label(botoneraPanel) => [
			text = "Orden ya emitida:"
			bindVisibleToProperty("ordenEmitida")
			fontSize = 7
			background = Color.ORANGE
		]
		new Label(botoneraPanel) => [
			bindVisibleToProperty("ordenEmitida") 
			bindValueToProperty("ordenDeArresto.responsable.nombre")
			fontSize = 9
			background = Color.ORANGE
		]
		new Button(botoneraPanel) => [
			caption = "Viajar"
			background = Color.ORANGE
			onClick[ | 
				close
				new ViajarDialog(this, new Viajar(modelObject)).open
			]
		]
		new Button(botoneraPanel) => [
			caption = "Expedientes"
			background = Color.ORANGE
			onClick[ |
				new ExpedientesSinEdicionWindow(this, modelObject.caso.expedientes).open
			]
		]
	}
	
	def createPistasPanel(Panel owner) {
		val pistasPanel = new Panel(owner) => [
			layout = new VerticalLayout
		]
		new Label(pistasPanel) => [
			text = "Lugares"
			fontSize = 12
			heigth = 30
		]
		
		modelObject.paisActual.lugares.forEach[l |
			new Button(pistasPanel) => [
				caption = l.nombreTipoLugar
				width = 150
				heigth = 36
				background = Color.ORANGE
				onClick[ |
					val visitarLugar = new VisitarLugar(modelObject, l)
					if (visitarLugar.puedeTerminarJuego) close
					new VisitarLugarDialog(this, visitarLugar).open
				]
			]
		]
	}
	
	def createRecorridoCriminalPanel(Panel owner) {
		val recorridoPanel = new Panel(owner) => [
			layout = new VerticalLayout
		]
		new Label(recorridoPanel) => [
			text = "Recorrído Criminal"
			foreground = Color.WHITE
			background = Color.ORANGE
		]
		new List<Pais>(recorridoPanel) => [
			bindItemsToProperty("recorridoCriminal").adapter = new PropertyAdapter(Pais, "nombre")
			width = 132
		]
	}

	def createDestinosFallidosPanel(Panel owner) {
		val fallidosPanel = new Panel(owner) => [
			layout = new VerticalLayout
		]
		new Label(fallidosPanel) => [
			text = "Destinos fallidos"
			foreground = Color.WHITE
			background = Color.ORANGE
		]
		new List<Pais>(fallidosPanel) => [
			bindItemsToProperty("destinosFallidos").adapter = new PropertyAdapter(Pais, "nombre")
			width = 132
		]
	}
	
}